﻿#region License
/* ---------------------------------------------------------------- *
 *
 * This file is part of the Xcoordination Application Space
 * ("XcoAppSpace") http://www.xcoordination.com
 *
 * Copyright (C) 2009 Xcoordination http://www.xcoordination.com
 *
 * XcoAppSpace is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General
 * Public License as published by the Free Software Foundation.
 *
 * XcoAppSpace is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/
 * or write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * ---------------------------------------------------------------- */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using XcoAppSpaces.Core.Base;
using XcoAppSpaces.Core.Configuration;

namespace XcoAppSpaces.Core
{
    /// <summary>
	/// The main class of XcoAppSpaces. XcoAppSpace represents the application space
	/// and allows running workers, as well as resolving worker that have already been
	/// started and connecting to workers running at a remote space. It also provides
	/// basic dependency injection container functionality.
	/// </summary>
	public class XcoAppSpace : XcoAppSpaceBase
    {
		static XcoAppSpace()
		{
			XcoAppSpacePlatfromSpecificConfig.Init();
		}

		/// <summary>
		/// Creates a new XcoAppSpace without remote communication functionality.
		/// </summary>
		public XcoAppSpace() : base() { }
        
		/// <summary>
		/// Creates a new XcoAppSpace by using the given config string.
		/// </summary>
		/// <param name="configString">The config string to configure the appspace instance.</param>
		public XcoAppSpace(string configString) : base(configString) { }

	    /// <summary>
	    /// Creates a new XcoAppSpace by using the given configuration.
	    /// </summary>
	    /// <param name="config">The configuration to use for this appspace instance.</param>
		public XcoAppSpace(IXcoConfiguration config) : base(config) { }

	    /// <summary>
		/// Creates an XcoAppSpace instance from the given configuration object.
		/// </summary>
		/// <param name="config">The configuration object.</param>
		/// <returns>The created XcoAppSpace instance.</returns>
		public static implicit operator XcoAppSpace(XcoFluentAppSpaceConfig config)
		{
			return new XcoAppSpace(config);
		}

		/// <summary>
		/// Creates an XcoAppSpace instance from the given configuration object.
		/// </summary>
		/// <param name="config">The configuration object.</param>
		/// <returns>The created XcoAppSpace instance.</returns>
		public static implicit operator XcoAppSpace(XcoFluentServiceConfig config)
		{
			return new XcoAppSpace(config);
		}

		#region Static Setup Methods

		/// <summary>
		/// Returns an XcoAppSpaceConfig object for configuring and creating a new space instance.
		/// </summary>
		public static XcoFluentAppSpaceConfig Configure
		{
			get { return new XcoFluentAppSpaceConfig(); }
		}

		/// <summary>
		/// Initializes the XcoAppSpace using the given config string.
		/// </summary>
		/// <param name="configString">The config string that should be used for initialization of the space.</param>
		/// <returns>An XcoAppSpaceConfiguration instance for further configuration of the space.</returns>
		public static XcoFluentAppSpaceConfig ConfigureWithConfigString(string configString)
		{
			return new XcoFluentAppSpaceConfig(configString);
		}

		#endregion
	}
}
